<?php
/**用户信息操作文件**/
require_once 'common.php';
function addUser($uname,$upass,$uemail,$headimg,$gender="1",$power="1"){
	$link=get_connect();
	$uname=mysql_dataCheck($uname);
	$upass=mysql_dataCheck($upass);
	$uemail=mysql_dataCheck($uemail);
	$headimg=mysql_dataCheck($headimg);
	$format="%Y-%m-%d %H:%M:%S";//设置时间格式
	$regtime=strftime($format); //获取系统时间
	$sql = "insert into `tbl_user` (`uname`,`upass`,`uemail`,`headimg`,`regtime`,`gender`,`power`) values ('$uname','$upass','$uemail','$headimg','$regtime',$gender,$power)";			
	$rs= execUpdate($sql,$link);
	return $rs; 
 }

function updateUser($uid,$uname,$upass,$uemail,$headimg,$gender,$power){
	$link=get_connect();
	$uname=mysql_dataCheck($uname);
	$upass=mysql_dataCheck($upass);
	$uemail=mysql_dataCheck($uemail);
	$headimg=mysql_dataCheck($headimg);
	//组合sql语句
	$sql = "update `tbl_user` set `uname`='$uname',`upass`='$upass',`uemail`='$uemail',`headimg`='$headimg',`gender`=$gender,`power`=$power where `uid`=$uid";	
    $rs=execUpdate($sql,$link);   
    return $rs;
 }
  
 function deleteUser($uid){
	 $sql="delete from `tbl_user` where `uid`=$uid";
	 $link=get_connect();
     $rs=execUpdate($sql,$link);   
     return $rs;
 }  
 
 function findUserByName($name){
  $link=get_connect();
  $name=mysql_dataCheck($name);
   $sql = "select `uid`,`uname`, 
  case 
    when gender=1 then '男' 
	when gender=2 then '女' end as `gender`,`upass`,`regtime`,`headimg`,`uemail`,
  case 
	when power=1 then '普通用户'
	when power=2 then '系统管理员' end as `power` from `tbl_user` where `uname`='$name'";
  
   $rs=execQuery($sql,$link);
   if(count($rs)>0){return $rs[0];}
   return $rs;
} 
function findUserById($uid){
   $sql = "select `uid`,`uname`, 
  case 
    when gender=1 then '男' 
	when gender=2 then '女' end as `gender`,`upass`,`regtime`,`headimg`,`uemail`,
  case 
	when power=1 then '普通用户'
	when power=2 then '系统管理员' end as `power` from `tbl_user` where `uid`=$uid";
   $link=get_connect();
   $rs=execQuery($sql,$link);
   if(count($rs)>0){return $rs[0];}
   return $rs;
} 

//////////////////////////////////////////////
//修改用户密码功能
/////////////////////////////////////////////
function updateUserpass($uid,$upass){
	$link=get_connect();	
	$upass=mysql_dataCheck($upass);	
	//组合sql语句
	$sql = "update `tbl_user` set `upass`='$upass' where `uid`=$uid";	
    $rs=execUpdate($sql,$link);   
    return $rs;
 }


///////////////////////////////
//修改用户信息功能(不包括密码)
/////////////////////////////
function updateUserInfo($uid,$uname,$uemail,$gender){
	$link=get_connect();
	$uname=mysql_dataCheck($uname);
	$uemail=mysql_dataCheck($uemail);
	
	//组合sql语句
	$sql = "update `tbl_user` set `uname`='$uname',`uemail`='$uemail',`gender`=$gender where `uid`=$uid";	
	echo $sql;
    $rs=execUpdate($sql,$link);   
    return $rs;
 }
?>